import java.io.*;
import java.util.*;

class Concordance
{
    private static Map<String, Vector<Token>> concordance = new VectorMapGeneric<String, Vector<Token>>();

    private static void add(String filename) throws FileNotFoundException
    {
        Tokenizer tokenizer = new Tokenizer(filename);

		while (tokenizer.hasNext())
        {
			Token token = tokenizer.next();
			Vector<Token> tokens = concordance.get(token.getWord());
			if (tokens == null) 
            {
                tokens = new Vector<Token>();
				concordance.put(token.getWord(), tokens);
            }
            tokens.add(token);
		}
    }
    
    private static void TestVectorMapGeneric() throws FileNotFoundException
    {
//        add("test.txt");
//        add("test2.txt");
        add("Token.java");
        add("Tokenizer.java");
        add("Concordance.java");

//		System.out.println(concordance);

		System.out.println("---------");
		for (Iterator<String> iter = concordance.keySet().iterator(); iter.hasNext(); )
        {
			String key = iter.next();
			System.out.println("word: \"" + key + "\":");
            for (Token token : concordance.get(key))
            {
                System.out.println("        " + token.getPlacement());
            }
            System.out.println();
		}
		System.out.println("---------");
    }

    public static void main(String [] args) throws Exception
    {
        TestVectorMapGeneric();
	}
}
